<!DOCTYPE hrml>
<html>
<head>
    <title>商品分类</title>
    <include file='public/head'>
    <style>
        .layui-legend-size{font-size:14px !important;}
        .layui-nopadding{padding:0 !important;}
        .layui-overflow{overflow:auto;}
        .layui-nomargin{margin: 0 !important;}
        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
        .layui-input{height:30px !important; }
        .layui-form-search-item .layui-inline{margin-bottom: 5px;} 
        .layui-form-search-item label{margin-left: 15px;}
        .layui-table-page {padding: 7px 0px 0px;}
        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
    </style>
</head>
<body>
    <!-- layui-tab开始 -->
    <div class="layui-tab" lay-fliter="demo-tab">
        <!-- 顶部导航菜单开始 -->
        <div class="layui-tab-nav">
            <ul class="layui-tab-title">
                {:getNav('goods','goods_comment/index')};
            </ul>
        </div>
        <!-- 内容开始 -->
        <div class="layui-card">
                <!-- 搜索栏开始 -->
                <fieldset class="layui-elem-field layui-field-title layui-field-padding">
                    <legend class="layui-legend-size">搜索</legend>
                    <form class="layui-form table-bar" action="{:cmf_plugin_url('Goods://goods_comment/index')}" lay-filter="form-bar" method="post">
                        <div class="layui-form-search-item">
                            <eq name="allow" value="true">
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select name="search[store_type]" lay-verify="" class="layui-input">
                                        <option value="1" <eq name="search.store_type" value="1">selected</eq> >店铺名称</option>
                                        <option value="2" <eq name="search.store_type" value="2">selected</eq> >店铺ID</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="search[store_title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.store_title}" style="width: 100px;">
                                </div>
                            </div>
                            </eq>
                            <label></label>
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select name="search[goods_type]" lay-verify="" class="layui-input">
                                        <option value="1" <eq name="search.goods_type" value="1">selected</eq> >商品名称</option>
                                        <option value="2" <eq name="search.goods_type" value="2">selected</eq> >商品ID</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="search[goods_title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.goods_title}" style="width: 100px;">
                                </div>
                            </div>
                            <label></label>
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select name="search[user_type]" lay-verify="" class="layui-input">
                                        <option value="1" <eq name="search.user_type" value="1">selected</eq> >用户昵称</option>
                                        <option value="2" <eq name="search.user_type" value="2">selected</eq> >用户ID</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="search[user_title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.user_title}" style="width: 100px;">
                                </div>
                            </div>
                            <label>时间</label>
                            <div class="layui-inline">
                                <div class="layui-input-inline" style="width:100px;">
                                <input type="text" class="layui-input" id="test2" name="search[start_time]" value="{$search.start_time}" autocomplete="off">
                                </div>
                            </div>—
                            <div class="layui-inline">
                                <div class="layui-input-inline" style="width:100px;">
                                <input type="text" class="layui-input" id="test3" name="search[end_time]" value="{$search.end_time}" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
                            <eq name="allow" value="true">
                            <input type="submit" style="font-weight:800;" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-primary " name="report" value="举报处理"/>
                            </div>
                            </eq>
                        </div>
                    </form>
                </fieldset>
                <!-- 搜索栏结束 -->
            <!-- 表头按钮开始 -->
            <div class="layui-card-header layui-bg-gray layui-bottom">
                <!-- <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger delete-btn" ><i class="layui-icon ">&#xe640;</i>批量删除</a>
                <a href="javascript:;" class="layui-btn layui-btn-xs config-btn" ><i class="layui-icon ">&#xe620;</i>配置</a> -->
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger all-delete-btn" ><i class="layui-icon ">&#xe60f;</i>批量隐藏</a>
                <a href="javascript:;" class="layui-btn layui-btn-xs all-reply-btn" ><i class="layui-icon ">&#xe63a;</i>批量回复</a>
            </div>
            <!-- 表头按钮结束 -->
            <!-- 数据表格开始 -->
            <form method="post" id="f">
            <table class="layui-table layui-nomargin">
                <thead>
                    <tr>
                        <th rowspan="2" style="text-align:center; width: 20px;">
                            <input type="checkbox"  id="check-box-all" >
                        </th>
                        <eq name="allow" value="true">
                        <th style="width:60px;">店铺名称(:ID)</th></eq>
                        <th style="width:45px;">商品ID</th>
                        <th>商品名称</th>
                        <th>商品规格</th>
                        <th>用户昵称</th>
                        <th>用户头像</th>
                        <th>评论时间</th>
                        <th >评分</th>
                        <th style="width:300px;">评论内容</th>
                        <th>评论图片</th>
                        <th style="width:60px;">是否匿名</th>
                        <eq name="allow" value="true">
                            <th style="width:40px;">回复</th>
                            <th style="width:40px;">举报</th>
                        </eq>
                        <th style="width:100px;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <volist  name="data" id="vo">
                        <tr lay-fliter="test3">
                            <th style="text-align:center;">
                                <input type="checkbox" class="check-box " name="id[]" value="{$vo['id']}">
                            </th>
                            <eq name="allow" value="true">
                            <td>{$vo.store_name}(ID:{$vo.store_id})</td></eq>
                            <td>{$vo.goods_id}</td>
                            <td>{$vo.goods_name}</td>
                            <td>{$vo.goods_spec}</td>
                            <td>{$vo.nick_name}</td>
                            <td><if condition="$vo.head_portrait neq ''"><img src="__ROOT__{$vo.head_portrait}" width="50"><else>无</if></td> 
                            <td>{:date('Y-m-d H:i:s',$vo.add_time)}</td>
                            <td>{$vo.score}</td>
                            <td>{$vo.comment}</td>
                            <td><if condition="$vo.img neq ''"><button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs photos-btn">照片</button><else>无</if></td>
                            <td>
                                <if condition="$vo.is_anonym eq 1">
                                    是<else>否
                                </if>
                            </td>
                            <eq name="allow" value="true">
                                <td>{$vo.reply} <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs view-btn">查看</button></td>
                                <td>{$vo.report}</td>
                            </eq>
                            <td>
                                <div class="layui-btn-group">
                                <if isset($report)> 
                                    <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs reset-btn" >清除举报</button> 
                                <else>
                                    <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs reply-btn" title="回复"><i class="layui-icon">&#xe611;</i></button>
                                </if>
                                <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" title="隐藏"><i class="layui-icon">&#xe60f;</i></button>
                                </div>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
            <!--分页开始-->
            <div class="layui-table-page">
                <div id="layui-table-page1">
                    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
                        {$page|default=''}
                    </div>
                </div>
            </div>
            <!-- 分页结束 -->
            </form>
            <!-- 数据表格结束 -->
        </div>
        <!-- 内容结束 -->
    </div>
    <!-- layui-tab结束 -->
    <include file='public/scripts'>
    <script>
    //全选/取消
    $('#check-box-all').on('click',function(){  
        console.log(1111);
        $('.check-box').prop('checked',$('#check-box-all').prop('checked'));
        console.log($('#check-box-all').prop('checked'));
    }); 
    layui.use('laydate', function(){
          var laydate = layui.laydate;
          //执行一个laydate实例
          laydate.render({
            elem: '#test2' //指定元素
          });
            //年月选择器
          laydate.render({
            elem: '#test3'
          });
        });
    function sort(){
        $("#f").submit();
    }
//批量回复用户评论
$('.all-reply-btn').on('click',function(){
    // let id = $(this).data('id');
    let id = $('#f').serialize();
    layer.prompt({
        formType: 2,
        value: '',
        title: '回复评论',
        offset:'130px',
        area: ['500px', '400px'] //自定义文本域宽高
        }, function(value, index, elem){
            $.ajax({
                url:"{:cmf_plugin_url('Goods://goods_comment/reply')}",
                type:'post',
                data: id+"&"+"comment="+value, //{id,comment:value},
                success:function(data){
                    let icon = ( data.status == 'success' ) ? 1 : 5 ;
                    layer.msg( data.message , { time:1200 , icon:icon, offset:'130px' },function(){
                        if (data.status == 'success') {
                            window.location.reload();
                        }
                    });
                },
                error:function(data){
                    console.log(data);
                    layer.msg('系统错误',{time:1200,icon:5,offset:'130px'});
                }
            }) 
        layer.close(index);
        });
});
    //回复用户评论
    $('.reply-btn').on('click',function(){
        let id = $(this).data('id');
        layer.prompt({
            formType: 2,
            value: '',
            offset:'130px',
            title: '回复评论',
            area: ['500px', '400px'] //自定义文本域宽高
            }, function(value, index, elem){
                $.ajax({
                    url:"{:cmf_plugin_url('Goods://goods_comment/reply')}",
                    type:'post',
                    data:{id:id,comment:value},
                    success:function(data){
                        let icon = ( data.status == 'success' ) ? 1 : 5 ;
                        layer.msg( data.message , { time:1200 , icon:icon , offset:'130px'},function(){
                            if (data.status == 'success') {
                                window.location.reload();
                            }
                        });
                    },
                    error:function(data){
                        console.log(data);
                        layer.msg('系统错误',{time:1200,icon:5, offset:'130px'});
                    }
                }) 
            layer.close(index);
            });
    });
    //编辑表单
    $('.photos-btn').on('click',function(){
        let id = $(this).data('id');
        let url = "{:cmf_plugin_url('Goods://goods_comment/editPage')}?id="+id;


        layer.open({
            type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            ,title: '评论照片'//层的标题
            ,shadeClose: true//是否点击遮罩关闭
            ,shade: 0.8//遮罩
            ,area: ['800px', '500px']//宽高
            ,offset:'130px'
            ,btn:false//弹框按钮
            // ,fixed:false//固定
            ,content: url //iframe的url
            // ,btn1:function(index, layero){
            // }
        });
    });
//删除
$('.all-delete-btn').on('click',function(){
    var id_str = $('input[type=checkbox]:checked').map(function(){return this.value}).get().join(',');
    var id = $('#f').serialize();
    // console.log(id_str);return false;
    // let id = $(this).data('id');
    // if(id == undefined) id = id_str;
    //询问
    layer.confirm('确定要隐藏吗？',{icon:3,title:'提示',btn:['确定','取消'], offset:'130px'}
    ,function(index,layero){
        $.ajax({
            url:"{:cmf_plugin_url('Goods://goods_comment/delete')}",
            type:'post',
            data:id,
            success:function(data){
                let icon = ( data.code == 200 ) ? 1 : 5 ;
                layer.msg( data.message , { time:1200 , icon:icon, offset:'130px' },function(){
                    if (data.code == 200) {
                        window.location.reload();
                    }
                });
            },
            error:function(data){
                console.log(data);
                layer.msg('系统错误',{time:1200,icon:5, offset:'130px'});
            }
        })   
    },function(index){});
})
//删除
$('.delete-btn').on('click',function(){
    var id_str = $('input[type=checkbox]:checked').map(function(){return this.value}).get().join(',');
    let id = $(this).data('id');
    if(id == undefined) id = id_str;
    //询问
    layer.confirm('确定要隐藏吗？',{icon:3,title:'提示',btn:['确定','取消'], offset:'130px'}
    ,function(index,layero){
        $.ajax({
            url:"{:cmf_plugin_url('Goods://goods_comment/delete')}",
            type:'post',
            data:{id:id},
            success:function(data){
                let icon = ( data.code == 200 ) ? 1 : 5 ;
                layer.msg( data.message , { time:1200 , icon:icon, offset:'130px' },function(){
                    if (data.code == 200) {
                        window.location.reload();
                    }
                });
            },
            error:function(data){
                console.log(data);
                layer.msg('系统错误',{time:1200,icon:5, offset:'130px'});
            }
        })   
    },function(index){});
})
    //配置页
    $('.config-btn').on('click',function(){
        let url = "{:cmf_plugin_url('Goods://goods_comment/configPage')}";
        layer.open({
            type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            ,title: '添加'//层的标题
            ,shadeClose: true//是否点击遮罩关闭
            ,shade: 0.8//遮罩
            ,area: ['800px', '500px']//宽高
            ,offset:'130px'
            ,btn:['提交','关闭']//弹框按钮
            ,fixed:false//固定
            ,content: url //iframe的url
            ,yes:function(index, layero){
            //子页面的请求操作都放子页面
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.tijiao();
            }
            ,btn2:function(index, layero){
            }
        });
    })
    //查看回复
    $('.view-btn').on('click',function(){
        let id = $(this).data('id');
        let url = "{:cmf_plugin_url('Goods://goods_comment/replyPage')}?id="+id;
        layer.open({
            type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            ,title: '查看回复'//层的标题
            ,shadeClose: true//是否点击遮罩关闭
            ,shade: 0.8//遮罩
            ,offset:'130px'
            ,area: ['800px', '700px']//宽高
            // ,btn:false//弹框按钮
            // ,fixed:false//固定
            ,content: url //iframe的url
            // ,btn1:function(index, layero){
            // }
        });
    })
    //清除举报处理
    $('.reset-btn').on('click',function(){
        let id = $(this).data('id');
        $.ajax({
                url:"{:cmf_plugin_url('Goods://goods_comment/reset')}",
                type:'post',
                data:{id:id},
                success:function(data){
                    let icon = ( data.status == 'success' ) ? 1 : 5 ;
                    layer.msg( data.message , { time:1200 , icon:icon, offset:'130px'},function(){
                        if (data.status == 'success') {
                            window.location.reload();
                        }
                    });
                },
                error:function(data){
                    console.log(data);
                    layer.msg('系统错误',{time:1200,icon:5, offset:'130px'});
                }
            }) 
    })
    </script>
</body>
</html>